package models

import "time"

type Suggestions struct {
	SuggestionID   uint64    `gorm:"column:suggestion_id;primary_key;auto_increment" json:"suggestion_id"`
	Content        string    `gorm:"column:content;not null" json:"content" `
	UserID         uint64    `gorm:"column:user_id;not null" json:"user_id"`
	RecipeID       uint64    `gorm:"column:recipe_id;" json:"recipe_id" `
	SuggestionDate time.Time `gorm:"column:suggestion_date;" json:"suggestion_date" `
}

// 提交建议
func (suggestion *Suggestions) Create() error {
	return DB.Self.Create(&suggestion).Error
}

// 删除建议
func (suggestion *Suggestions) Delete() error {
	return DB.Self.Delete(&suggestion).Error
}

// 查询个人提交的建议
func GetSuggestionByUserId(userId uint64) ([]*Suggestions, error) {
	suggestions := make([]*Suggestions, 0)
	err := DB.Self.Where("user_id = ?", userId).Find(&suggestions).Error
	return suggestions, err
}

// 查询关于食谱的建议
func GetSuggestionByRecipeId(recipeId uint64) ([]*Suggestions, error) {
	suggestions := make([]*Suggestions, 0)
	err := DB.Self.Where("recipe_id = ?", recipeId).Find(&suggestions).Error
	return suggestions, err
}
